<?php
class Record extends CI_Controller {
	
	private $user_id;
	
	public function __construct()
	{
		parent::__construct();
		$this->user_utils->filter_login();
		$this->user_id = $this->user_utils->get_session_attribute(Variable::SESSION_USER_ID);
		
		$this->load->model('record_model');
		$this->load->model('tag_model');
	}
	
	public function index()
	{
		$this->detail();
	}
	
	public function add()
	{
		$tag = $this->input->get_post('tag');
		$memory = $this->input->get_post('memory');
		$description = $this->input->get_post('description');

		$this->load->library('service/record_service');
		$this->record_service->add_record($this->user_id, $memory, $description, $tag);
		
		$data['type'] = 'add';
		$data['tag_list'] = $this->tag_model->get_tag_list($this->user_id);
		$data['result'] = 'true';
		$this->load->view('record/result', $data);
	}
	
	public function update()
	{
		$record_id = $this->input->post('recordId');
		$tag = $this->input->post('tag');
		$memory = $this->input->post('memory');
		$description = $this->input->post('description');
			
		$this->load->library('service/record_service');
		$this->record_service->update_record($this->user_id, $record_id, $memory, $description, $tag);
		
		$data['type'] = 'update';
		$data['tag_list'] = $this->tag_model->get_tag_list($this->user_id);
		$data['result'] = 'true';
		$this->load->view('record/result', $data);
	}
	
	public function del()
	{
		$record_id = $this->input->post('recordId');
		
		$this->load->library('service/record_service');
		$this->record_service->del_record($this->user_id, $record_id);
		
		$data['type'] = 'del';
		$data['result'] = 'true';
		$this->load->view('record/result', $data);
	}
	
	public function detail($record_id = 0)
	{
		$data['type'] = 'record';
		$data['record'] = $record_id == 0 ? false : $this->record_model->get_record_by_id($record_id);
		$data['tag_list'] = $this->tag_model->get_tag_list($this->user_id);
		$data['view'] = 'record/detail';
		$this->load->view('member/index', $data);	
	}
}
?>